package com.only4play.portal.cp.bean.message.jsonmessage;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.only4play.common.utils.Base64Utils;
import com.only4play.portal.common.api.PortalConstants;
import com.only4play.portal.cp.config.CpConfigStorage;
import lombok.Getter;
import lombok.Setter;


@Getter
@Setter
public class CpJsonOutTextMessage extends CpJsonOutMessage {

    private String content;

    public CpJsonOutTextMessage() {
        this.msgType = PortalConstants.JsonMsgType.TEXT;
    }

    @Override
    public String toEncrypted(CpConfigStorage cpConfigStorage) {
        try {
            String encode = Base64Utils.encode(this.content);
            this.setContent(encode);
            ObjectMapper objectMapper = new ObjectMapper();
            return objectMapper.writeValueAsString(this);
        } catch (Exception exception) {
            return "";
        }
    }
}
